package com.fyt.reachgo.controller;

import com.fyt.reachgo.domain.Result;
import com.fyt.reachgo.domain.TravelComment;
import com.fyt.reachgo.domain.dto.CommentDTO;
import com.fyt.reachgo.service.TravelCommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/comments")
@RequiredArgsConstructor
public class CommentController {

    private final TravelCommentService commentService;


    // 获取路书评论列表
    @PostMapping("/guide/{guideId}")
    public Result<List<TravelComment>> getCommentsByGuideId(
            @PathVariable Integer guideId,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size) {
        return Result.success(commentService.getCommentsByGuideId(guideId, page, size));
    }

    // 添加评论
    @PostMapping("/add")
    public Result<Long> addComment(@RequestBody @Valid CommentDTO commentDTO) {
        return Result.success(commentService.addComment(commentDTO));
    }

    // 点赞评论
    @PostMapping("/like/{commentId}")
    public Result likeComment(@PathVariable Long commentId) {

        return commentService.likeComment(commentId);
    }

    // 取消点赞
    @PostMapping("/unlike/{commentId}")
    public Result<Void> unlikeComment(@PathVariable Long commentId) {

        return commentService.unlikeComment(commentId);
    }
//
//    // 删除评论
//    @DeleteMapping("/{commentId}")
//    public Result<Void> deleteComment(@PathVariable Long commentId) {
//        commentService.deleteComment(commentId);
//        return Result.success();
//    }
}
